chroot() can fail and its return value should be checked against, in that case
do an exit() since this is a fatal condition that we cannot recover from.
Fixes: 63789e51ed91 ("init: add support for sysupgrades triggered from preinit")
Reviewed-by: Matthias Schiffer <[email protected]>
Signed-off-by: Florian Fainelli <[email protected]>
{
char *wdt_fd = watchdog_fd();
char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
+ int ret;
- if (chroot(prefix)) {
+ ret = chroot(prefix);
+ if (ret < 0) {
fprintf(stderr, "Failed to chroot for upgraded exec.\n");
return;
}
fprintf(stderr, "Failed to exec upgraded.\n");
unsetenv("WDTFD");
watchdog_set_cloexec(true);
- chroot(".");
+ ret = chroot(".");
+ if (ret < 0) {
+ fprintf(stderr, "Failed to reset chroot, exiting.\n");
+ exit(EXIT_FAILURE);
+ }
}